home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1996, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
-
- /* sharpen_texutre.c - simple program to demonstrate texture sharpening
- *
- * Escape key - exit the program
- * <s> key - cycle through sharpen filters
- */
-
- #include <GL/gl.h>
- #include <GL/glu.h>
- #include <GL/glut.h>
-
- #include <stdlib.h>
- #include <stdio.h>
-
- /* Function Prototypes */
-
- GLvoid initgfx( GLvoid );
- GLvoid drawScene( GLvoid );
- GLvoid reshape( GLsizei, GLsizei );
- GLvoid keyboard( GLubyte, GLint, GLint );
-
- void printHelp( char * );
-
- /* Global Definitions */
-
- #define KEY_ESC 27 /* ascii value for the escape key */
-
- /* tree texture: high alpha in foreground, zero alpha in background */
- #define B 0x00000000
- #define F 0xA0A0A0ff
-
- /* Global Variables */
-
- static unsigned int tex[] = {
- B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,
- B,B,B,B,B,B,B,F,F,B,B,B,B,B,B,B,
- B,B,B,B,B,B,B,F,F,B,B,B,B,B,B,B,
- B,B,B,B,B,B,F,F,F,F,B,B,B,B,B,B,
- B,B,B,B,B,B,F,F,F,F,B,B,B,B,B,B,
- B,B,B,B,B,F,F,F,F,F,F,B,B,B,B,B,
- B,B,B,B,B,F,F,F,F,F,F,B,B,B,B,B,
- B,B,B,B,F,F,F,F,F,F,F,F,B,B,B,B,
- B,B,B,B,F,F,F,F,F,F,F,F,B,B,B,B,
- B,B,B,F,F,F,F,F,F,F,F,F,F,B,B,B,
- B,B,B,F,F,F,F,F,F,F,F,F,F,B,B,B,
- B,B,F,F,F,F,F,F,F,F,F,F,F,F,B,B,
- B,B,F,F,F,F,F,F,F,F,F,F,F,F,B,B,
- B,B,B,B,B,B,F,F,F,F,B,B,B,B,B,B,
- B,B,B,B,B,B,F,F,F,F,B,B,B,B,B,B,
- B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,
- };
-
- static GLboolean sharpen_texture_supported = GL_TRUE;
-
- GLvoid
- main( int argc, char *argv[] )
- {
- GLsizei width, height;
-
- glutInit( &argc, argv );
-
- width = glutGet(GLUT_SCREEN_WIDTH);
- height = glutGet(GLUT_SCREEN_HEIGHT);
- glutInitWindowPosition( width / 4, height / 4);
- glutInitWindowSize( width / 2, height / 2 );
- glutInitDisplayMode( GLUT_RGBA );
- glutCreateWindow( argv[0] );
-
- initgfx();
-
- glutKeyboardFunc( keyboard );
- glutReshapeFunc( reshape );
- glutDisplayFunc( drawScene );
-
- printHelp( argv[0] );
-
- glutMainLoop();
- }
-
- GLvoid
- printHelp( char *progname )
- {
- fprintf(stdout, "\n%s - uses sharpen texture extension to display "
- "a texture\n\n"
- "<s> key - cycle through sharpen filters\n"
- "Escape key - exit the program\n\n",
- progname);
-
- fprintf( stdout, "Magnification filter is GL_LINEAR\n" );
- }
-
- void
- initgfx(void)
- {
- /* use alpha test to discard background pixels */
- glEnable(GL_ALPHA_TEST);
- glAlphaFunc(GL_GEQUAL, 0.3);
-
- glEnable(GL_TEXTURE_2D);
-
- glClearColor(0.0, 0.0, 0.0, 1.0);
-
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-
- if (!glutExtensionSupported("GL_SGIS_sharpen_texture")) {
- fprintf(stderr,
- "\nGL_SGIS_sharpen_texture not supported on this machine\n");
- sharpen_texture_supported = GL_FALSE;
- }
-
- /* generate mipmaps; levels 0 and 1 are needed for sharpening */
- gluBuild2DMipmaps(GL_TEXTURE_2D, 4, 16, 16, GL_RGBA, GL_UNSIGNED_BYTE,
- tex);
- }
-
- void
- cycleMagFilter( void )
- {
- static GLint filter = GL_LINEAR;
-
- #ifdef GL_SGIS_sharpen_texture
- if (sharpen_texture_supported) {
- switch (filter) {
- case GL_LINEAR:
- filter = GL_LINEAR_SHARPEN_SGIS;
- fprintf( stdout,
- "Magnification filter is GL_LINEAR_SHARPEN_SGIS\n" );
- break;
- case GL_LINEAR_SHARPEN_SGIS:
- /* sharpening just alpha is useful for keeping the tree
- * outline crisp
- */
- filter = GL_LINEAR_SHARPEN_ALPHA_SGIS;
- fprintf( stdout,
- "Magnification filter is GL_LINEAR_SHARPEN_ALPHA_SGIS\n" );
- break;
- case GL_LINEAR_SHARPEN_ALPHA_SGIS:
- filter = GL_LINEAR_SHARPEN_COLOR_SGIS;
- fprintf( stdout,
- "Magnification filter is GL_LINEAR_SHARPEN_COLOR_SGIS\n" );
- break;
- case GL_LINEAR_SHARPEN_COLOR_SGIS:
- filter = GL_LINEAR;
- fprintf( stdout,
- "Magnification filter is GL_LINEAR\n" );
- break;
- }
- } else {
- printf("GL_SGIS_sharpen_texture is not supported\n");
- }
- #endif
-
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter );
- }
-
- GLvoid
- keyboard( GLubyte key, GLint x, GLint y )
- {
- switch (key) {
- case 's':
- cycleMagFilter();
- glutPostRedisplay();
- break;
- case KEY_ESC: /* Exit whenever the Escape key is pressed */
- exit(0);
- }
- }
-
- GLvoid
- reshape( GLsizei width, GLsizei height )
- {
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- gluPerspective(60.0, (GLdouble)width/height, 1.0, 10.0 );
- glMatrixMode(GL_MODELVIEW);
- glTranslatef(0.,0.,-2.5);
- }
-
- void
- drawScene( GLvoid )
- {
- glClear(GL_COLOR_BUFFER_BIT);
- glBegin(GL_TRIANGLE_STRIP);
- glTexCoord2f( 0, 1); glVertex2f(-1,-1);
- glTexCoord2f( 0, 0); glVertex2f(-1, 1);
- glTexCoord2f( 1, 1); glVertex2f( 1,-1);
- glTexCoord2f( 1, 0); glVertex2f( 1, 1);
- glEnd();
- glFlush();
-
- checkError("drawScene");
- }
-